function y = cvc_epoch_binary(EEG,fieldname,values_1,values_0)
% CVC_EPOCH_BINARY
%
%  Synopsis
%  ========
% 
%  y = cvc_epoch_binary(EEG,fieldname,values_1,values_0)
%
%  -- Author: Mads Dyrholm --
%     Center for Visual Cognition, University of Copenhagen.
%     May 2010
%
%  Purpose
%  =======
%
%  Inputs
%  ======
%
%  fieldname - String, the name of the EEG.epoch(:).XXXX field.
%
%  values_1 - Cell array of strings, the values which will produce
%  a 1 in y.
%
%  values_0 - Same as values_1, but produces 0s instead of 1s.

y = [];
for trial=1:EEG.trials
  eval(sprintf('fieldvalue = EEG.epoch(trial).%s;',fieldname));
  if any(strcmp(fieldvalue,values_1))
    y = cat(2,y,1);
  elseif any(strcmp(fieldvalue,values_0))
    y = cat(2,y,0);
  else
    error('Some trial did not have value_1 nor value_0.');
  end
end

